#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<assert.h>
using namespace std;

class SeqList
{
public:
	SeqList()
	{
		_a = nullptr;
		_size = 0;
		_capacity = 0;
	}
	void PushBack(int x)
	{
		if (_size == _capacity)
		{
			int newcapacity = _capacity == 0 ? 4 : _capacity * 2;
			int* tmp = (int*)realloc(_a, sizeof(int) * newcapacity);
			if (tmp == nullptr)
			{
				perror("realloc fail");
				exit(-1);
			}
			_a = tmp;
			_capacity = newcapacity;
		}
		_a[_size++] = x;
	}
	int Size()const
	{
		return _size;
	}
	const int& operator[](size_t s)const
	{
		assert(s < _size);
		return _a[s];
	}
	int& operator[](size_t s)
	{
		assert(s < _size);
		return _a[s];
	}
private:
	int* _a ;
	int _size ;
	int _capacity;
};
void Print(const SeqList& s)
{
	for (int i = 0; i < s.Size(); i++)
	{
		cout << s[i]<< " ";
	}
}
int main()
{
	SeqList q;
	q.PushBack(1);
	q.PushBack(2);
	q.PushBack(3);
	q.PushBack(4);
	for (int i = 0; i < q.Size(); i++)
	{
		cout << q[i] << " ";
	}
	cout << endl;
	for (int i = 0; i < q.Size(); i++)
	{
		cout << ++q[i] << " ";
	}
	cout << endl;
	Print(q);
	return 0;
}
